#include "AutoMOBY.h"
#include "Error.h"

bool AutoMOBY::Start( void )
{
	int Error = 0;
	bool ExError = false;
	
	printf( "%s\n", "Enabling debug privilege > ..." );
	Error = Util::EnableDebugPrivilege( true );
	if( Error != TRUE )
		return Error::PrintError( Error );
	else
		printf( "%s\n", "\t\tSuccessfully enabled debug privilege!" );

	printf( "\n%s\n", "Stage 1 > Deleting HShield files: ehsvc.dll, HSUpdate.exe, and hshield.log..." );
	Error = HShield::DeleteFiles( );
	if( Error != TRUE )
		return Error::PrintError( Error );
	else
		printf( "%s\n", "\t\tSuccessfully deleted HShield files!" );

	printf( "\n%s\n", "Stage 2 > Downloading Original HShield files..." );
	Error = HShield::DownloadOriginalFiles( );
	if( Error != TRUE )
		return Error::PrintError( Error );
	else
		printf( "%s\n", "\t\tSuccessfully downloaded original HShield files!" );

	printf( "\n%s\n", "Stage 3 > Launching Maple..." );
	ExError = WatchDog::LaunchMaple( );
	if( ExError != true )
		return Util::PrintReturn< bool >( "\t\tError, failed to launch Maple!", false );
	else
		printf( "%s\n", "\t\tSuccessfully launched Maple!" );

	printf( "\n%s\n", "Stage 4 > Waiting for 45 minutes - do not exit Maple's process..." );
	ExError = WatchDog::WatchFor45Minutes( );
	if( ExError != true )
		return Util::PrintReturn< bool >( "\t\tError, failed to wait for 45 minutes ( Maple closed )!", false );
	else
		printf( "%s\n", "\t\tSuccessfully waited for 45 minutes!" );

	printf( "\n%s\n", "Stage 5 > Deleting HShield files: ehsvc.dll and HSUpdate.exe..." );
	Error = HShield::DeleteFiles( );
	if( Error != TRUE )
		return Error::PrintError( Error );
	else
		printf( "%s\n", "\t\tSuccessfully deleted HShield files..." );

	printf( "\n%s\n", "Stage 6 > Downloading MOBY ( Moose's Bypass ) files..." );
	Error = HShield::DownloadMOBYFiles( );
	if( Error != TRUE )
		return Error::PrintError( Error );
	else
		printf( "%s\n", "\t\tSuccessfully downloaded MOBY ( Moose's Bypass ) files..." );

	printf( "\n%s\n", "Completed > Re-Launching Maple..." );
	ExError = WatchDog::LaunchMaple( );
	if( ExError != true )
		return Util::PrintReturn< bool >( "\t\tError, failed to launch Maple - please manually launch Maple!", true );

	return true;
}